package com.raising.framework.entity;

import java.io.Serializable;

/**
 * 接口返回数据对象
 * @author GaoYuan
 * @date 2018/11/26 下午2:02
 */
public class ResultVo implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 结果0-失败，1-成功
	 */
	private int ret;
	/** 返回码 */
	private int code;
	/** 提示 */
	private String msg;
	/** 描述 */
	private String desc;
	/** 结果数据 */
	private Object data;
	
	public static final int SUCCESS = 1;
	public static final int FAILURE = 0;

	/** 成功 */
	public static final int CODE_OK = 200;
	/** 程序异常 */
	public static final int CODE_ERROR = 500;
	/** 数据不存在 */
	public static final int CODE_NOT_EXIST = 700;
	/** 没有权限 */
	public static final int CODE_NO_PERMISSION = 900;
	/** 不满足参数要求 */
	public static final int CODE_NO_PARAMS = 800;


	public ResultVo(int ret, int code, String msg, Object data) {
		super();
		this.code = code;
		this.msg = msg;
		this.ret = ret;
		this.data = data;
	}
	public ResultVo(int ret, String msg, Object data) {
		super();
		this.code = CODE_OK;
		this.msg = msg;
		this.ret = ret;
		this.data = data;
	}
	
	public ResultVo() {
		super();
	}

	public ResultVo(ResultCode resultCode){
		this.code = resultCode.getCode();
		this.msg = resultCode.getMsg();
		this.desc = resultCode.getDesc();
		this.data = null;
	}

	/************************************* 快捷方法 ******************************************/
	/** 成功 */
	public static ResultVo success(){
		return new ResultVo(ResultCode.OK).ret(ResultVo.SUCCESS).desc("操作成功");
	}
	/** 失败 - 自定义错误 */
	public static ResultVo failure(ResultCode resultCode){
		return new ResultVo(resultCode).ret(ResultVo.FAILURE);
	}
	/** 错误 - 系统异常错误 */
	public static ResultVo error(){
		return new ResultVo(ResultCode.SYSTEM_ERR).ret(ResultVo.FAILURE);
	}


	/** 自定义提示语 - 英文 */
	public ResultVo msg(String msg){
		this.msg = msg;
		return this;
	}
	/** 自定义提示描述语 - 中文 */
	public ResultVo desc(String desc){
		this.desc = desc;
		return this;
	}
	/** 自定义返回值 */
	public ResultVo data(Object data){
		this.data = data;
		return this;
	}

	/** 自定义返回标识 */
	private ResultVo ret(int ret){
		this.ret = ret;
		return this;
	}

	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public int getRet() {
		return ret;
	}
	public void setRet(int ret) {
		this.ret = ret;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
}
